package dk.Utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;

//这是PoiExcel的工具类
public class POIUtils {
     /**
      * 
      * @param path 文件路径
      * @param path 表头名称
      * @param SheetName 工作表名称
      * @param clazz 映射的实体类
      * @param list  元数据
      * @throws IOException
      */
	public static void WriteToFile(String path,String TableName,String SheetName,Class clazz,List list) throws IOException {
		
		ExportParams exportparams = new ExportParams(TableName, SheetName);
		Workbook exportExcel = ExcelExportUtil.exportExcel(exportparams,clazz,list);
		FileOutputStream file = new FileOutputStream(path);
		exportExcel.write(file);
		file.close();
		System.out.println("文件写入成功");
	}
	public static List GetObjectListFromFile(String path,Object object,Integer titlerows,Integer headRows) {
		Class clazz = object.getClass();
		ImportParams importParams = new ImportParams();
		importParams.setTitleRows(titlerows);
		importParams.setHeadRows(headRows);
		List<Object> list = ExcelImportUtil.importExcel(new File(path), Object.class,importParams);
		return list;
	}
}
